import Navs from "./nav.json";
export const navs = Navs;

const registerRoute = groups => {
  let routes = [];
  groups.map(nav => {
    let subPath = {
      path: `/${nav.path}`,
      component: require(`./../views/${nav.path}.vue`),
      name: nav.title || nav.name,
      meta: {
        title: nav.title || nav.name,
        description: nav.description,
        icon: nav.icon
      }
    };
    if (nav.redirect) {
      subPath.redirect = nav.redirect;
    }
    subPath.children = [];

    let groupItems = nav.children;
    if (groupItems) {
      groupItems.map(nav => {
        let currentUrl = "";
        let pathObj = {
          path: `${nav.path}`,
          component: require(`./../views/${nav.path}.vue`),
          name: nav.title || nav.name,
          meta: {
            title: nav.title || nav.name,
            description: nav.description,
            icon: nav.icon
          }
        };
        try {
          subPath.children.push(pathObj);
        } catch (e) {
          console.error(e);
          nav.disabled = true;
        }
      });
    }
    routes.push(subPath);
  });
  return routes;
};

const routes = registerRoute(Navs);

// routes.push({
//   path: "/home",
//   component: require("./../views/home.vue"),
//   name: "home",
//   meta: {
//     title: "Home",
//     description: "Home blog"
//   }
// });
routes.push({
  path: "/",
  component: require("./../views/main.vue"),
  name: "main",
  meta: {
    title: "main",
    description: "main blog"
  },
  redirect: 'main/index'
});



routes.push({
  path: "*",
  component: require("./../views/404.vue"),
  name: "404",
  meta: {
    title: "",
    description: ""
  }
});

export default routes;
